import numpy as np
import pandas as pd
from pandas import Series,DataFrame

obj = Series([4.5, 7.2, -5.3, 3.6], index=['d', 'b', 'a', 'c'])

print obj

obj2 = obj.reindex(['a', 'b', 'c', 'd', 'e'])
print obj2

obj3 = obj.reindex(['a', 'b', 'c', 'd', 'e'], fill_value=0)
print obj3

obj4 = Series(['blue', 'purple', 'yellow'], index=[0, 2, 4])
print obj4
print obj4.reindex(range(6), method='ffill')

print "-------------------------------------------------"

frame = DataFrame(np.arange(9).reshape((3,3)), index=['a', 'c', 'd'], columns=['Hoio', 'Texas', 'California'])
print frame
frame2 = frame.reindex(['a', 'b', 'c', 'd'])
print frame2

states = ['Texas', 'Utah', 'California']
print frame.reindex(columns=states)


obj = Series(np.arange(5.), index=['a', 'b', 'c', 'd', 'e'])
print obj
new_obj = obj.drop('c')
print new_obj

print obj.drop(['d', 'c'])

print "-------------------------------------------------"

data = DataFrame(np.arange(16).reshape((4,4)),index=['Ohio', 'Colorado', 'Utha', 'New Your'],
                 columns=['one', 'two', 'three', 'four'])

print data
print data.drop(['Colorado', 'Ohio'])
print data.drop('two', axis=1)
print data.drop(['two', 'four'], axis=1)

print "-------------------------------------------------"

data = DataFrame(np.arange(16).reshape((4,4)),index=['Ohio', 'Colorado', 'Utha', 'New Your'],
                 columns=['one', 'two', 'three', 'four'])
print data
print data['two']
print data[['two', 'three']]
print data[:2]
print data['three'] > 5
print data<5


data = DataFrame(np.arange(16).reshape((4,4)),index=['Ohio', 'Colorado', 'Utha', 'New Your'],
                 columns=['one', 'two', 'three', 'four'])
print data
print data[data < 5]

print data.ix['Colorado', ['two', 'three']]
print type(data.ix['Colorado', ['two', 'three']])
print data.ix[['Colorado', 'Utah'], [3, 0, 1]]

print "-------------------------------------"
s1 = Series([7.3, -2.5, 3.4, 1.5], index=['a', 'c', 'd', 'e'])
s2 = Series([-2.1, 3.6, -1.5, 4, 3.1], index=['a', 'c', 'e', 'f', 'g'])
print s1
print s2
print s1+s2

print "--------------------------------------"

arr =np.arange(12.).reshape((3,4))
print arr
print arr[0]
print arr - arr[0]

print "-----------------------------------------"
frame = DataFrame(np.random.randn(4, 3), columns=list('bde'), index=['Uhtah', 'Ohio', 'Texas', 'Oregon'])
print frame
print np.abs(frame)
# lambda
f = lambda x: x.max() - x.min()

print frame.apply(f)
print frame.apply(f, axis=1)


